package com.zzyy.study.controller;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2025-02-21 12:18
 */
@RestController
@Slf4j
public class HelloLangChain4JController
{

    @Resource
    private ChatLanguageModel chatLanguageModel;

    // http://localhost:9001/langchain4j/hello?prompt=如何学习阿里云
    @GetMapping(value = "/langchain4j/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        String result = chatLanguageModel.generate(prompt);

        System.out.println("通过langchain4j调用模型返回结果：\n"+result);

        return result;
    }



    @GetMapping(value = "/langchain4j/hello2")
    public String hello2()
    {
        String result = chatLanguageModel.generate("你好，我爱吃西瓜");
        String result2 = chatLanguageModel.generate("我爱吃什么");

        System.out.println("11111\n"+result);
        System.out.println();
        System.out.println();
        System.out.println("2222\n"+result2);

        return result;
    }
}
